Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't inline when compiling with Clang #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vmx
Copy link

@vmx vmx commented Jul 8, 2014

Clang has a different behaviour than GCC when it comes to inlining functions.
Sadly Clang identifies itself as GNUC, hence the define to prevent non-GCC
compilers to use the inline keyword didn't work.

This commit solves the problem with adding an additional check to the define,
that the compiler isn't Clang.

During compilation you get warnings like:

In file included from linux_sigar.c:30:
../../../include/sigar_util.h:80:20: warning: inline function 'sigar_skip_token' is not defined
      [-Wundefined-inline]
SIGAR_INLINE char *sigar_skip_token(char *p);
               ^
linux_sigar.c:137:24: note: used here
            if ((ptr = sigar_skip_token(ptr))) {
                       ^

Which end up in an error like:

libtool: link: clang -g -O2 -o .libs/cpuinfo cpuinfo.o  ../src/.libs/libsigar.so
../src/.libs/libsigar.so: undefined reference to `sigar_skip_token'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Clang has a different behaviour than GCC when it comes to inlining functions.
Sadly Clang identifies itself as __GNUC__, hence the define to prevent non-GCC
compilers to use the inline keyword didn't work.

This commit solves the problem with adding an additional check to the define,
that the compiler isn't Clang.

During compilation you get warnings like:

    In file included from linux_sigar.c:30:
    ../../../include/sigar_util.h:80:20: warning: inline function 'sigar_skip_token' is not defined
          [-Wundefined-inline]
    SIGAR_INLINE char *sigar_skip_token(char *p);
                   ^
    linux_sigar.c:137:24: note: used here
                if ((ptr = sigar_skip_token(ptr))) {
                           ^

Which end up in an error like:

    libtool: link: clang -g -O2 -o .libs/cpuinfo cpuinfo.o  ../src/.libs/libsigar.so
    ../src/.libs/libsigar.so: undefined reference to `sigar_skip_token'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
lizhanyin added a commit to lizhanyin/sigar that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant